/**
 * create by young (young2f@outlook.com) on 2020/12/4
 * 任务绩效考核表
 */
'use strict';
const model = require('../base/tModelBase');
const _ = require('lodash');
module.exports = app => {
  const mongoose = app.mongoose;
  const schema = mongoose.Schema;
  const connect = app.mongooseDB.get('pmcBus');
  const json = {
    treeId: { type: String, _type: 'code', title: '编码', required: true },
    recordId: { type: String, _type: 'code', title: '编码', required: true },
    name: { type: String, _type: 'string', title: '姓名',required: true , enableArea: [ 'table', 'detail', 'search' ] },
    date: { type: Date, _type: 'date', title: '日期',  required: true, enableArea: [ 'table', 'detail', 'search' ] },
    salesTotalAmount: { type: Number, _type: 'number', title: '本月销售总金额', required: true  , enableArea: [ 'table', 'detail',  ] },
    oldCustomerSalesTotalAmount: { type: Number, _type: 'number', title: '本月老客户销售额', required: true  , enableArea: [ 'table', 'detail', ] },
    newCustomerSalesTotalAmount: { type: Number, _type: 'number', title: '本月新客户销售额', required: true  , enableArea: [ 'table', 'detail',  ] },
    customerTotalCount: { type: Number, _type: 'number', title: '本月总客户数', required: true  , enableArea: [ 'table', 'detail',] },
    newCustomerNoStandardCount: { type: Number, _type: 'number', title: '本月不达标新客户数', required: true  , enableArea: [ 'table', 'detail', ] },
    newCustomerStandardCount: { type: Number, _type: 'number', title: '本月达标新客户数', required: true  , enableArea: [ 'table', 'detail', ] },
    salesAmountExamine: { type: Number, _type: 'number', title: '本月销售额考核', required: true  , enableArea: [ 'table', 'detail',  ] },
    salesAmountExamineActualDeduction: { type: Number, _type: 'number', title: '本月销售额考核实际扣款', required: true  , enableArea: [ 'table', 'detail', ] },
    oldCustomerDealExamine: { type: Number, _type: 'number', title: '本月成交老客户考核', required: true  , enableArea: [ 'table', 'detail',  ] },
    oldCustomerExamineActualDeduction: { type: Number, _type: 'number', title: '本月老客户考核实际扣款', required: true  , enableArea: [ 'table', 'detail',  ] },
    newCustomerExamine: { type: Number, _type: 'number', title: '本月新客户考核', required: true  , enableArea: [ 'table', 'detail',] },
    newCustomerExamineActualDeduction: { type: Number, _type: 'number', title: '本月新客户考核实际扣款', required: true  , enableArea: [ 'table', 'detail',  ] },

    kpiAmount: { type: Number, _type: 'number', title: '本月绩效总金额', required: true  , enableArea: [ 'table', 'detail',  ] },
    kpiActualAmount: { type: Number, _type: 'number', title: '本月实际绩效总金额', required: true  , enableArea: [ 'table', 'detail', ] },

    fileList: { type: Array, _type: 'fileList', title: '图片列表' },
  };
  const _model = _.cloneDeep(model);
  _.assign(_model, json);
  const _schema = new schema(
    _model,
    { timestamps: { createdAt: 'createdTs', updatedAt: 'updatedTs' } }
  );
  return connect.model('DicPerTaskKPI', _schema);
};
